package cn.gemiman.daoyi.module.cms.dal.mysql.blogtalk;

import cn.gemiman.daoyi.framework.common.pojo.PageResult;
import cn.gemiman.daoyi.framework.mybatis.core.mapper.BaseMapperX;
import cn.gemiman.daoyi.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.gemiman.daoyi.module.cms.controller.admin.blogtalk.vo.BlogTalkPageReqVO;
import cn.gemiman.daoyi.module.cms.dal.dataobject.blogtalk.BlogTalkDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 说说 Mapper
 *
 * @author 道一源码
 */
@Mapper
public interface BlogTalkMapper extends BaseMapperX<BlogTalkDO> {

    default PageResult<BlogTalkDO> selectPage(BlogTalkPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BlogTalkDO>()
                .eqIfPresent(BlogTalkDO::getUserType, reqVO.getUserType())
                .eqIfPresent(BlogTalkDO::getUserId, reqVO.getUserId())
                .likeIfPresent(BlogTalkDO::getUserNickname, reqVO.getUserNickname())
                .eqIfPresent(BlogTalkDO::getAppSiteId, reqVO.getAppSiteId())
                .eqIfPresent(BlogTalkDO::getAppId, reqVO.getAppId())
                .eqIfPresent(BlogTalkDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BlogTalkDO::getApproveStatus, reqVO.getApproveStatus())
                .eqIfPresent(BlogTalkDO::getCreatorIp, reqVO.getCreatorIp())
                .eqIfPresent(BlogTalkDO::getCreatorCity, reqVO.getCreatorCity())
                .betweenIfPresent(BlogTalkDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(BlogTalkDO::getSort)
                .orderByDesc(BlogTalkDO::getId));
    }

    @Update("update cms_blog_talk set thumbs_up_times = thumbs_up_times + 1 where id = #{id}")
    void updateThumbsUpTimes(@Param("id") Long id);
}
